<?php
namespace Admin\Controller;

class OrderController extends CommonController{

    /*订单列表*/
    public function index(){

        $this->where = array();
        $this->where['order_type'] = array('neq',3);
        $this->where['status'] = I('status');
        I('get.keywords') && $this->where['order_sn'] = I('get.order_sn');
        $this->order = 'create_time desc';
        parent::index(); 
    }

    public function save(){
        $item = D('Order')->where(array('id'=>I('id')))->relation('perinfo')->find();
        $this->assign('item',$item);
        $this->display();
    }

    public function send_goods(){
        $this->assign('id',(int)I('post.id'));
        $this->assign('info',D('Order')->where(array('id'=>I('post.id')))->find());
        $this->display();
    }

      public function do_send_goods(){
        $data = I('post.info');
        $data['send_time'] = date("Y-m-d H:i:s");
        $res = D('Order')->save($data);
        $res === false ? $this->error('发货失败') : $this->success('发货成功');
    }

    //物流接口
    public function logistics(){
        $info = D('Order')->where(array('id'=>I('order_id')))->find();
        $wl = pinyin1($info['logistics_company']);   //取快递公司的首字母
        $key = '1c8e4867536c5d222dbb7331434195fd';
        $type = 'json';
        $res = curl_request('http://v.juhe.cn/exp/index?com='.$wl.'&no='.$info['logistics_number'].'&type='.$type.'&key='.$key);
        $arr = json_decode($res,true);
        $this->assign('info',$arr);
        $this->assign('pic',$info['goods_pic']);
        $this->display();

    }
}
?>